๋ฌธ์
H-Index๋ ๊ณผํ์์ ์์ฐ์ฑ๊ณผ ์ํฅ๋ ฅ์ ๋ํ๋ด๋ ์งํ์
๋๋ค. ์ด๋ ๊ณผํ์์ H-Index๋ฅผ ๋ํ๋ด๋ ๊ฐ์ธ h๋ฅผ ๊ตฌํ๋ ค๊ณ ํฉ๋๋ค. ์ํค๋ฐฑ๊ณผ์ ๋ฐ๋ฅด๋ฉด, H-Index๋ ๋ค์๊ณผ ๊ฐ์ด ๊ตฌํฉ๋๋ค.
์ด๋ค ๊ณผํ์๊ฐ ๋ฐํํ ๋
ผ๋ฌธ nํธ ์ค, h๋ฒ ์ด์ ์ธ์ฉ๋ ๋
ผ๋ฌธ์ด hํธ ์ด์์ด๊ณ ๋๋จธ์ง ๋
ผ๋ฌธ์ด h๋ฒ ์ดํ ์ธ์ฉ๋์๋ค๋ฉด h์ ์ต๋๊ฐ์ด ์ด ๊ณผํ์์ H-Index์
๋๋ค.
์ด๋ค ๊ณผํ์๊ฐ ๋ฐํํ ๋ ผ๋ฌธ์ ์ธ์ฉ ํ์๋ฅผ ๋ด์ ๋ฐฐ์ด citations๊ฐ ๋งค๊ฐ๋ณ์๋ก ์ฃผ์ด์ง ๋, ์ด ๊ณผํ์์ H-Index๋ฅผ return ํ๋๋ก solution ํจ์๋ฅผ ์์ฑํด์ฃผ์ธ์.
์ ํ์ฌํญ
- ๊ณผํ์๊ฐ ๋ฐํํ ๋ ผ๋ฌธ์ ์๋ 1ํธ ์ด์ 1,000ํธ ์ดํ์ ๋๋ค.
- ๋ ผ๋ฌธ๋ณ ์ธ์ฉ ํ์๋ 0ํ ์ด์ 10,000ํ ์ดํ์ ๋๋ค.
์ ์ถ๋ ฅ ์
| citations | return |
|---|---|
| [3, 0, 6, 1, 5] | 3 |
๐ Logic
private boolean isHindex(int[] citations, int H) {
int s = 0, l = 0;
for (int i = 0; i < citations.length; i++) {
if (citations[i] >= H) l++;
if (citations[i] <= H) s++;
}
if (l >= H && s <= H) return true;
return false;
}
H๊ฐ ์ฃผ์ด์ง H-index ์กฐ๊ฑด์ ๋ง์กฑํ๋์ง ํ์ธํ๋ ํจ์
๐ CODE
์ฝ๋ ๋ณด๊ธฐ/์ ๊ธฐ๐ซ
import java.util.*;
class Solution {
public int solution(int[] citations) {
int n = citations.length;
int answer = 0;
Arrays.sort(citations);
for (int i = citations[n - 1]; i >= 0; i--) {
if (isHindex(citations, i)) {
answer = i;
break;
}
}
return answer;
}
private boolean isHindex(int[] citations, int H) {
int s = 0, l = 0;
for (int i = 0; i < citations.length; i++) {
if (citations[i] >= H) l++;
if (citations[i] <= H) s++;
}
if (l >= H && s <= H) return true;
return false;
}
}
โ๏ธ Review
- H-index๊ฐ ์ฃผ์ด์ง
citations๋ฐฐ์ด์ ์์ ์๋ ์๋ค๋ ์๊ฐ์ ๋ชปํ๊ณ , ์ฃผ์ด์ง ๋ฐฐ์ด ๋ด์์๋ง H-index๋ฅผ ์ฐพ์ผ๋ ค๋ค๊ฐ ํ ์ผ 1๊ฐ ๋นผ๊ณ ๋ค ์คํจํ๋ค... - ์ฃผ์ด์ง ๋ฐฐ์ด์ ์์ ์๋ ์๋ค๋ ๊ฐ์ ํ์ ๊ตฌํํ๋ ๋ฐ๋ก ํด๊ฒฐํ๋ค.
๐ ์ถ์ฒ
Programmers : https://programmers.co.kr/learn/courses/30/lessons/42747